import api from '../../../api/index';
Page({
	/**
   * 页面的初始数据
   */
	data: {
    defaultImageUrl: 'https://hxhealth.oss-cn-beijing.aliyuncs.com/redstart/pages/error2.png',
    getvideolist: [],
    tags: ''
	},

	/**
   * 生命周期函数--监听页面加载
   */
	onLoad(options) {
    console.log('onLoad')
    const {tags} = options
    this.setData({
      tags
    })
  },
  handleImageError: function(e) {
    console.log(e);
    this.setData({
      imageUrl: this.data.defaultImageUrl // 将图片路径设置为默认图片路径
    });
  },
  errorFunction: function (event) {
    console.log(event);
    var index = event.currentTarget.dataset.index
    var images = 'getvideolist['+ index +'].images'
    this.setData({
      [images]: 'https://hxhealth.oss-cn-beijing.aliyuncs.com/redstart/pages/error2.png'
    })
  },
	/**
     * 获取视频列表
     */
	async getLiveData() {
		// console.log('getBanner')
		try {
			const getvideolist = await this.getvideoload();
      console.log(getvideolist);
      for (let i = 0; i < getvideolist.length; i++) {
        if(!getvideolist[i].images) {
          getvideolist[i].images = 'https://hxhealth.oss-cn-beijing.aliyuncs.com/redstart/pages/error2.png'
        } 
      }
      console.log(getvideolist);
			this.setData({
				getvideolist
			});
		} catch (e) {
			console.error(e);
		}
  },
  async getvideoload() {
    try {
      const res = await api.post('/api/hxhealth/sportvideo/group', {
          data: {
              'tags': this.data.tags
          }
      })
      return res
  } catch (e) {
      console.log('getvideoload->', e)
      return null
  }
  },
  async getvideoloadmoren() {
    try {
      const res = await api.post('/api/hxhealth/sportvideo/group', {
          data: {
              'tags': '日常调养'
          }
      })
      return res
  } catch (e) {
      console.log('getvideoload->', e)
      return null
  }
  
  },
  go(e) {
    console.log(e.currentTarget.dataset);
    const {titlename,video,content,id} = e.currentTarget.dataset
    console.log(titlename);
    wx.navigateTo({
      url: `/sportsClass/pages/video/index?titlename=${titlename}&articleId=${id}&video=${video}&content=${content}`
  })
  },
  goChange() {
    wx.navigateTo({
      url: `/sportsClass/pages/height/index`
  })
  },
	/**
   * 生命周期函数--监听页面初次渲染完成
   */
	onReady() {},

	/**
   * 生命周期函数--监听页面显示
   */
	onShow() {
    console.log('onshow')
    this.getLiveData();
    if (!wx.getStorageSync('userInfo')) {
      this.setData({
        showchange: false
      })
      this.getLiveData();
    } else {
      this.getLiveData();
      this.setData({
        showchange: true
      })
    }
		
  },

	/**
   * 生命周期函数--监听页面隐藏
   */
	onHide() {},

	/**
   * 生命周期函数--监听页面卸载
   */
	onUnload() {},

	/**
   * 页面相关事件处理函数--监听用户下拉动作
   */
	onPullDownRefresh() {},

	/**
   * 页面上拉触底事件的处理函数
   */
	onReachBottom() {},

	/**
   * 用户点击右上角分享
   */
	onShareAppMessage() {}
});
